<?php
namespace app\admin\controller;

use app\admin\model\User as ModelUser;
use Atlaxy\Controller;
use think\captcha\Captcha;
use think\facade\Session;

class User extends Controller
{
    public function captcha()
    {
        return Captcha::create();    
    }
    
    public function login()
    {
        if($this->request->isGet()){
            $this->fetch();
        }else{
            $data = $this->request->post();
            // halt($data['captcha']);
            if(!captcha_check($data['captcha'])){
                $this->jsonFail("验证码错误");
            }
               
            $model = new ModelUser;
            if($model->login($data)){
                $this->jsonSucc();
            }else{
                $this->jsonFail($model->getError());
            }
        }
    }
}